﻿namespace In66.Net.Share.Authentication.Handlers
{
    public class BearerTokenGenerator : ITokenGenerator
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly ILogger<BearerTokenGenerator> _logger;

        public BearerTokenGenerator(
            IHttpContextAccessor httpContextAccessor,
             ILogger<BearerTokenGenerator> logger)
        {
            _httpContextAccessor = httpContextAccessor;
            _logger = logger;
        }

        public static string Scheme => "Bearer";

        public string GeneratorName => Scheme;

        public virtual string? Create()
        {
            var token = _httpContextAccessor.HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var tokenTxt = token?.Remove(0, 7);
            _logger.LogDebug($"Accessor:{tokenTxt}");
            return tokenTxt;
        }
    }
}
